#include "headers.h"

#define tabuaLarg 284.0
#define tabuaComp 142.0
#define tabuaAlt 10.0
#define altTopoMesa 100.0


GLubyte *greenTexture;
GLubyte *woodTexture1;
GLubyte *woodTexture2;
GLubyte *woodTexture3;
GLubyte *woodTexture4;
GLubyte *woodTexture5;

void mesa(void)
{
  /*
  glPushMatrix();
  //glColor3f(1.0, 1.0, 1.0);
  glColor3f(0.0, 1.0, 0.0);
  //funcPrism(4, tabuaBase, tabuaAltura);
  glTranslatef(0.0, 100.0, 0.0);
  funcDrawParalel(1, tabuaLarg, tabuaAlt, tabuaComp);
  glPopMatrix();
  */


  glPushMatrix();
  textureLoad(greenTexture);
  glTranslatef(0.0, altTopoMesa, 0.0);
  glColor3f(0., .6, 0.);
  funcDrawParalel(1, 300, 15, 160);
  //funcDrawParalel(1, tabuaLarg, tabuaAlt, tabuaComp);
  textureUnload();
  glPopMatrix();


  /*
   * Desenha a base de madeira logo abaixo da parte verde.
   */
  textureLoad(woodTexture4);
  glPushMatrix();
  glTranslatef(0.0, 92.5, 0.0);
  glColor3f(1, 1, 1);
  funcDrawParalel(1, 302, 10, 162);
  glPopMatrix();
  
  /*
   * Desenha uma outra parte abaixo da parte de madeira acima.
   */
  glPushMatrix();
  glTranslatef(0.0, 77.0, 0.0);
  glColor3f(1, 1, 1);
  funcDrawParalel(1, 280, 25, 130);
  glPopMatrix();
  textureUnload();

  desenhaPernas();
  desenhaBordas();
  desenhaCacapa();
}


void desenhaPernas (void)
{
  GLfloat coord[6][3] = {{-133.0f, 46.25f, 62.0f}, {133.0f, 46.25f, 62.0f},
                         {-133.0f, 46.25f,-62.0f}, {133.0f, 46.25f,-62.0f},
			 {   0.0f, 46.25f, 62.0f}, {  0.0f, 46.25f,-62.0f}};
  int i;

  textureLoad (woodTexture1);
  for (i = 0; i < 6; i++) {
    glPushMatrix();
    glTranslatef(coord[i][0], coord[i][1], coord[i][2]);
    glColor3f(1, 1, 1);
    funcDrawParalel(1, 25, 92.5, 25);
    glPopMatrix();
  }
  textureUnload();

  textureLoad(woodTexture4);
  for (i = 0; i < 6; i++) {
    glPushMatrix();
    //glColor3f(0.09f, 0.05f, 0.0f);
    glColor3f(1.0f, 1.0f, 1.0f);
    glTranslatef(coord[i][0], 0.0, coord[i][2]);
    glScalef (0.3, .039, 0.3);
    glutSolidCube (100);
    glPopMatrix();
  }
  textureUnload();
}


void desenhaBordas (void)
{
  CarregaTextura_semRepeticao (woodTexture1);

  glColor3f(1,1,1);

  /* lateral interna maior 1*/
  glPushMatrix();
  glTranslatef(70.5, altTopoMesa + 5, 77);
  funcDrawParalel(1, 126, 16, 12);
  glPopMatrix();
  
  /* lateral interna maior 2*/
  glPushMatrix();
  glTranslatef(-70.50, altTopoMesa + 5, -77);
  funcDrawParalel(1, 126, 16, 12);
  glPopMatrix();

  /* lateral interna maior 3*/
  glPushMatrix();
  glTranslatef(-70.5, altTopoMesa + 5, 77);
  funcDrawParalel(1, 126, 16, 12);
  glPopMatrix();
  
  /* lateral interna maior 4*/
  glPushMatrix();
  glTranslatef(70.50, altTopoMesa + 5, -77);
  funcDrawParalel(1, 126, 16, 12);
  glPopMatrix();
 
  /* lateral interna menor 1*/
  glPushMatrix();
  glTranslatef(147, altTopoMesa + 5, 0);
  funcDrawParalel(1, 12, 16, 129);
  glPopMatrix();

  /* lateral interna menor 2*/
  glPushMatrix();
  glTranslatef(-147, altTopoMesa + 5, 0);
  funcDrawParalel(1, 12, 16, 129);
  glPopMatrix();

  /* lateral externa menor 1*/
  glPushMatrix();
  glTranslatef(-151.5, altTopoMesa + 5, 0);
  funcDrawParalel(1, 6, 16, 162);
  glPopMatrix();

  /* lado externa lateral menor 2*/
  glPushMatrix();
  glTranslatef(151.5, altTopoMesa + 5, 0);
  funcDrawParalel(1, 6, 16, 162);
  glPopMatrix();

  /* lateral externa maior 1*/
  glPushMatrix();
  glTranslatef(0, altTopoMesa + 5, 80);
  funcDrawParalel(1, 308, 16, 6);
  glPopMatrix();

  /* lateral externa maior 2*/
  glPushMatrix();
  glTranslatef(0, altTopoMesa + 5, -80);
  funcDrawParalel(1, 308, 16, 6);
  glPopMatrix();

  textureUnload();
}


void desenhaCacapa (void)
{
  GLUquadricObj *qobj;
  
  glColor3f(0., 0., 0.);

  gluQuadricDrawStyle(qobj, GLU_FILL);
  glPushMatrix ();
  glTranslatef (0. , altTopoMesa + 8.1, 75.);
  glRotatef(90, 1, 0, 0);    
  gluDisk(qobj, 0.0, 7.5, 50, 100);
  glPopMatrix ();

  glPushMatrix ();
  glTranslatef (0., altTopoMesa + 8.1, -75.);
  glRotatef(90, 1, 0, 0);    
  gluDisk(qobj, 0.0, 7.5, 50, 100);
  glPopMatrix ();

  glPushMatrix ();
  glTranslatef (144., altTopoMesa + 8.1, 73.);
  glRotatef(90, 1, 0, 0);    
  gluDisk(qobj, 0.0, 9, 50, 100);
  glPopMatrix ();

  glPushMatrix ();
  glTranslatef (-144, altTopoMesa + 8.1, 73);
  glRotatef(90, 1, 0, 0);    
  gluDisk(qobj, 0.0, 9, 50, 100);
  glPopMatrix ();

  glPushMatrix ();
  glTranslatef (144, altTopoMesa + 8.1, -73);
  glRotatef(90, 1, 0, 0);    
  gluDisk(qobj, 0.0, 9, 50, 100);
  glPopMatrix ();

  glPushMatrix ();
  glTranslatef (-144, altTopoMesa + 8.1, -73);
  glRotatef(90, 1, 0, 0);    
  gluDisk(qobj, 0.0, 9, 50, 100);
  glPopMatrix ();

}


void initPoolTable(void)
{
  greenTexture = LoadBMP("textures/feltro.bmp");
  woodTexture1 = LoadBMP("textures/madeira1.bmp");
  woodTexture2 = LoadBMP("textures/madeira2.bmp");
  woodTexture3 = LoadBMP("textures/madeira3.bmp");
  woodTexture4 = LoadBMP("textures/madeira4.bmp");
  woodTexture5 = LoadBMP("textures/madeira5.bmp");
}
